<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
        <h2>表属性</h2>
        <form action="{:url('submitEditStructureTableAction')}" method="post" >
            <input type="hidden" name="table_id" value="{$table.id}">
            <div>
                <label for="id">ID</label>
                <input type="text" id="id" name="id" value="<?php if(isset($table)&&isset($table['id'])) echo $table['id'];?>" disabled readonly/>
            </div>
            <div>
                <label for="name">名称</label>
                <input type="text" id="name" name="name" value="<?php if(isset($table)&&isset($table['name'])) echo $table['name'];?>"/>
            </div>
            <div>
                <label for="title">标题</label>
                <input type="text" id="title" name="title" value="<?php if(isset($table)&&isset($table['title'])) echo $table['title'];?>"/>
            </div>
            <div>
                <label for="describe">描述</label>
                <input type="text" id="describe" name="describe" value="<?php if(isset($table)&&isset($table['describe'])) echo $table['describe'];?>"/>
            </div>
            <div>
                <label for="primary_key_field">主键字段</label>
                <input type="text" id="primary_key_field" name="primary_key_field" value="<?php if(isset($table)&&isset($table['primary_key_field'])) echo $table['primary_key_field'];?>"/>
            </div>
            <div>
                <label for="user_id_field">用户ID字段</label>
                <input type="text" id="user_id_field" name="user_id_field" value="<?php if(isset($table)&&isset($table['user_id_field'])) echo $table['user_id_field'];?>"/>
            </div>
            <div>
                <label for="create_time_field">创建时间字段</label>
                <input type="text" id="create_time_field" name="create_time_field" value="<?php if(isset($table)&&isset($table['create_time_field'])) echo $table['create_time_field'];?>"/>
            </div>
            <div>
                <label for="update_time_field">修改时间字段</label>
                <input type="text" id="update_time_field" name="update_time_field" value="<?php if(isset($table)&&isset($table['update_time_field'])) echo $table['update_time_field'];?>"/>
            </div>
            <button type="submit">提交</button>
        </form>
    </div>
    
    <div>
        <h2>字段</h2>
        <table>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>别名</th>
                <th>标题</th>
                <th>描述</th>
                <th>数据类型</th>
                <th>最大长度</th>
                <th>能否为空</th>
                <th>类型</th>
                <th>类型参数</th>
                <th>操作</th>
            </tr>
            <foreach name="fields" item="item">
            <tr>
                <td>{$item.id}</td>
                <td>{$item.name}</td>
                <td>{$item.alias}</td>
                <td>{$item.title}</td>
                <td>{$item.describe}</td>
                <td>{$item.data_type}</td>
                <td>{$item.max_length}</td>
                <td>{$item.is_nullable}</td>
                <td>{$item.type}</td>
                <td>{$item.type_params}</td>
                <td><a href="{:url('showEditStructureFieldPage',['field_id'=>$item['id']])}">修改</a></td>
            </tr>
            </foreach>
        </table>
        <a data-href="{:url('showCreateStructureFieldPage',['table_id'=>$table['id']])}">添加字段</a>
    </div>
    
    <div>
        <h2>场景</h2>

        <div>
            <h4>基本设置</h4>
            <table>
                <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>标题</th>
                    <th>描述</th>
                    <th>权限</th>
                    <th>参数</th>
                    <th>操作</th>
                </tr>
                <foreach name="scenes" item="item">
                <tr>
                    <td>{$item.id}</td>
                    <td>{$item.name}</td>
                    <td>{$item.title}</td>
                    <td>{$item.describe}</td>
                    <td>{$item.auth}</td>
                    <td>{$item.params}</td>
                    <td>
                        <a href="{:url('showEditScenePage',['scene_id'=>$item['id']])}">修改</a>
                        <a href="{:url('submitRemoveSceneAction',['scene_id'=>$item['id']])}">删除</a>
                        <a href="{:url('showCreateActionPage',['table_id'=>$table['id'],'scene_id'=>$item['id']])}">添加操作</a>
                        <a href="{:url('execCreateUserActionGroup',['table_id'=>$table['id'],'scene_id'=>$item['id']])}">创建用户操作组</a>
                        <a href="{:url('execCreateOwnerActionGroup',['table_id'=>$table['id'],'scene_id'=>$item['id']])}">创建所有者操作组</a>
                    </td>
                </tr>
                </foreach>
            </table>
            <a href="{:url('showCreateScenePage',['table_id'=>$table['id']])}">添加场景</a>
        </div>

        <div>
            <h4>场景关联字段</h4>
            <table>
                <tr>
                    <th>场景</th>
                    <th>属性</th>
                    <foreach name="fields" item="field">
                    <th>{$field.title}</th>
                    </foreach>
                    <th>操作</th>
                </tr>
                <foreach name="scenes" item="scene">
                <form action="{:url('submitEditSceneFieldAction',['scene_id'=>$scene['id']])}" method="post">
                    <tr>
                        <td rowspan="3">{$scene.title}</td>
                        <td>可读</td>
                        <?php $checkeds=explode(",",$scene["readable"]);  ?>
                        <foreach name="fields" item="field">
                        <?php $is_checked = in_array($field["id"],$checkeds) ? "checked" : "" ; ?>
                        <td><input type="checkbox" name="readable[{$field.id}]" id="" {$is_checked} ></td>
                        </foreach>
                        <td rowspan="3"><button type="submit">提交</button></td>
                    </tr>
                    <tr>
                        <td>可写</td>
                        <?php $checkeds=explode(",",$scene["writable"]);  ?>
                        <foreach name="fields" item="field">
                            <?php $is_checked = in_array($field["id"],$checkeds) ? "checked" : "" ; ?>
                        <td><input type="checkbox" name="writable[{$field.id}]" id="" {$is_checked} ></td>
                        </foreach>
                    </tr>
                    <tr>
                        <td>必填</td>
                        <?php $checkeds=explode(",",$scene["required"]);  ?>
                        <foreach name="fields" item="field">
                            <?php $is_checked = in_array($field["id"],$checkeds) ? "checked" : "" ; ?>
                        <td><input type="checkbox" name="required[{$field.id}]" id="" {$is_checked} ></td>
                        </foreach>
                    </tr>
                </form>
                </foreach>
            </table>
        </div>

    </div>

    <div>
        <h2>操作</h2>
        <div>
            <h4>基本设置</h4>
            <table>
                <tr>
                    <th>ID</th>
                    <th>场景</th>
                    <th>名称</th>
                    <th>标题</th>
                    <th>描述</th>
                    <th>权限</th>
                    <th>打开方式</th>
                    <th>操作类型</th>
                    <th>数据绑定</th>
                    <th>参数</th>
                    <th>操作</th>
                </tr>
                <foreach name="actions" item="item">
                <tr>
                    <td>{$item.id}</td>
                    <td>{$item.scene_id}</td>
                    <td>{$item.name}</td>
                    <td>{$item.title}</td>
                    <td>{$item.describe}</td>
                    <td>{$item.auth}</td>
                    <td>{$item.target_type}</td>
                    <td>{$item.action_type}</td>
                    <td>{$item.data_type}</td>
                    <td>{$item.params}</td>
                    <td>
                        <a href="{:url('showEditActionPage',['action_id'=>$item['id']])}">修改</a>
                        <a href="{:url('submitRemoveActionAction',['action_id'=>$item['id']])}">删除</a>
                        <if condition="in_array($item['target_type'],['show','form','href'])&&in_array($item['data_type'],['nope','where'])">
                            <a href="{:url('action/open',['action_id'=>$item['id']])}">预览</a>
                        </if>
                    </td>
                </tr>
                </foreach>
            </table>
        </div>

        <div>
            <h4>操作绑定操作</h4>
            <table>
                <tr>
                    <th>\</th>
                    <foreach name="actions" item="to_action">
                    <th>{$to_action.title}</th>
                    </foreach>
                    <th>操作</th>
                </tr>
                <foreach name="actions" item="from_action">
                <if condition="in_array($from_action['target_type'],['form','post','exec','link'])">
                <form action="{:url('submitEditActionBindAction',['action_id'=>$from_action['id']])}" method="post">
                    <tr>
                        <td>{$from_action.title}</td>
                        <foreach name="actions" item="to_action">
                        <?php 
                            $is_checked = $to_action["id"] === $from_action["bind_action"] ? "checked" : "" ;
                            $is_disabled = "" ;
                            if($to_action["id"] === $from_action["id"]){
                                $is_disabled = "disabled" ;
                            }
                            elseif($from_action["target_type"] === "form" && $to_action["target_type"] !== "post"){
                                $is_disabled = "disabled" ;
                            }
                        ?>
                        <td><input type="radio" name="bind_action" id="" value="{$to_action.id}" {$is_checked} {$is_disabled}></td>
                        </foreach>
                        <td><button type="submit">提交</button></td>
                    </tr>
                </form>
                </if>
                </foreach>
            </table>
        </div>

        <div>
            <h4>操作关联操作</h4>
            <table>
                <tr>
                    <th>\</th>
                    <foreach name="actions" item="to_action">
                    <if condition="$to_action['target_type']!=='post'">
                    <th>{$to_action.title}</th>
                    </if>
                    </foreach>
                    <th>操作</th>
                </tr>
                <foreach name="actions" item="from_action">
                <if condition="in_array($from_action['target_type'],['show','form'])">
                <form action="{:url('submitEditActionLinkAction',['action_id'=>$from_action['id']])}" method="post">
                    <tr>
                        <td>{$from_action.title}</td>
                        <?php $checkeds=explode(",",$from_action["link_action"]);  ?>
                        <foreach name="actions" item="to_action">
                        <if condition="$to_action['target_type']!=='post'">
                        <?php 
                            $is_checked = in_array($to_action["id"],$checkeds) ? "checked" : "" ;
                            $is_disabled = "";
                        ?>
                        <td><input type="checkbox" name="link_action[{$to_action.id}]" id="" {$is_checked} {$is_disabled}></td>
                        </if>
                        </foreach>
                        <td><button type="submit">提交</button></td>
                    </tr>
                </form>
                </if>
                </foreach>
            </table>
        </div>
    </div>

    <div>
        <h2>搜索</h2>
        <div>
            <h4>基本设置</h4>
            <table>
                <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>标题</th>
                    <th>描述</th>
                    <th>类型</th>
                    <th>指定字段</th>
                    <th>参数</th>
                    <th>操作</th>
                </tr>
                <foreach name="filters" item="item">
                <tr>
                    <td>{$item.id}</td>
                    <td>{$item.name}</td>
                    <td>{$item.title}</td>
                    <td>{$item.describe}</td>
                    <td>{$item.type}</td>
                    <td>{$item.fields}</td>
                    <td>{$item.params}</td>
                    <td>
                        <a href="{:url('showEditFilterPage',['filter_id'=>$item['id']])}">修改</a>
                        <a href="{:url('submitRemoveFilterAction',['filter_id'=>$item['id']])}">删除</a>
                    </td>
                </tr>
                </foreach>
            </table>
            <a href="{:url('showCreateFilterPage',['table_id'=>$table['id']])}">添加操作</a>
        </div>

        <div>
            <h4>操作关联搜索</h4>
            <table>
                <tr>
                    <th>\</th>
                    <foreach name="filters" item="filter">
                    <th>{$filter.title}</th>
                    </foreach>
                    <th>操作</th>
                </tr>
                <foreach name="actions" item="action">
                <if condition="in_array($action['target_type'],['show','form'])">
                <form action="{:url('submitEditActionFilterAction',['action_id'=>$action['id']])}" method="post">
                    <tr>
                        <td>{$action.title}</td>
                        <?php $checkeds=explode(",",$action["bind_filter"]);?>
                        <foreach name="filters" item="filter">
                        <?php $is_checked = in_array($filter["id"],$checkeds) ? "checked" : "" ;?>
                        <td><input type="checkbox" name="bind_filter[{$filter.id}]" id="" {$is_checked}></td>
                        </foreach>
                        <td><button type="submit">提交</button></td>
                    </tr>
                </form>
                </if>
                </foreach>
            </table>
        </div>

    </div>
</body>
</html>
